import unittest
import config
from common.dbutils import DBUtil

from common.common_assert import common_assert
from api.login import LoginAPI
from api.staff import StaffAPI
class TestStaffAPI(unittest.TestCase):
    TOKEN=None
    ID=None
    @classmethod
    def setUp(self) -> None:
        print(DBUtil().exe_sql("DELETE from bs_user where mobile = '13111147901';"))
    @classmethod
    def tearDownClass(cls) -> None:
        print(DBUtil().exe_sql("DELETE from bs_user where mobile = '13111147901';"))
    def test00_login_sucess(self):
        login_data = {"mobile": "13800000002", "password": "123456"}
        response=LoginAPI().login(login_data)
        print(response.json().get("data"))
        print(response.json())
        TestStaffAPI.TOKEN=response.json().get("data")
        # common_assert(self, response, 200, True, 10000, "成功")
    def test01_add_staff(self):

        add_data = {
            "username":"jack0709t2",
            "mobile":"13587146901",
            "timeOfEntry":"2020-07-09",
            "formOfEmployment":1,
            "workNumber":"10086",
            "departmentName":"销售",
            "departmentId":"1266699057968001024",
            "correctionTime":"2020-07-30T16:00:00.000Z"
        }

        response=StaffAPI().add_staff(add_data,TestStaffAPI.TOKEN)
        print(response.json())
        TestStaffAPI.ID=response.json().get("data").get("id")
        print(TestStaffAPI.ID)
    def test02_update_staff(self):
        update_data={"username":"rose609"}
        response=StaffAPI().update_staff(TestStaffAPI.ID,update_data,TestStaffAPI.TOKEN)
        print(response.json())
        # common_assert(self,response,200,True,10000,"成功")
    def test03_select_staff(self):
        response=StaffAPI().select_staff(TestStaffAPI.ID,TestStaffAPI.TOKEN)
        print(response.json())
    def test04_delete_staff(self):
        response=StaffAPI().delete_staff(TestStaffAPI.ID,TestStaffAPI.TOKEN)
        print(response.json())






